/*
 * dumpPhraseDictionary.cpp
 *
 *  Created on: Dec 16, 2012
 *      Author: m
 */

#include <iostream>
#include "../../src/physical_layer/file_system/PhraseDictionary.h"

#define ATTR_DELIM '|'

using physical::Phrase;
using physical::PhraseDictionary;

/**
 * Programa para dumpear el contenido de un diccionario de frases
 *
 * Uso : dumpPhraseDictionary <diccionario de frases> <archivo de salida>
 */

int main ( int argc, const char *argv[] )
{
    if ( argc != 3 )
    {
        std::cerr << "Argumentos inválidos." << std::endl;

        std::cerr << "Uso : dumpPhraseDictionary <diccionario de frases> <archivo de salida>" << std::endl;

        exit( 1 );
    }

    PhraseDictionary dictionary( argv[1], std::ios_base::in | std::ios_base::out);

    std::ofstream out ( argv[2], std::ios_base::out | std::ios_base::trunc );

    PhraseDictionary::Record record = dictionary.getFirst();

    do
    {
        Phrase phrase = record.get();
        out << record.getPosition() << ATTR_DELIM
            << phrase.getAuthorName() << ATTR_DELIM
            << phrase.getAuthorSurname() << ATTR_DELIM
            << phrase.getText() << std::endl;
    }
    while ( dictionary.hasNext(record) && (record = dictionary.getNext(record)) == record );

    out.close();
    dictionary.close();

    return 0;
}
